﻿using System;
using Enyim.Caching;
using System.Web.Mvc;
using SilenthinkContract;
using System.Collections.Generic;

namespace Web.Controllers
{
    public class CacheController : BaseController
    {
        public CacheController(ILogService logService, IBaseService baseService, IExtraService extraService, IStoreService storeService, IOrderService orderService, IGameService gameService, IAuctionService auctionService, IPassportService passportService, IPaymentService paymentService, IMemcachedClient memcachedClient) : base(logService, baseService, extraService, storeService, orderService, gameService, auctionService, passportService, paymentService, memcachedClient)
        {
        }

        public void Index()
        {

        }
        public string Count(string param)
        {
            var model = 0;
            switch (param)
            {
                case "base":
                    model = BaseService.GetCachedSQLCount();
                    break;
                case "store":
                    model = StoreService.GetCachedSQLCount();
                    break;
                case "passport":
                    model = PassportService.GetCachedSQLCount();
                    break;
                case "order":
                    model = OrderService.GetCachedSQLCount();
                    break;
                case "extra":
                    model = ExtraService.GetCachedSQLCount();
                    break;
            }
            return model.ToString();
        }

        public ActionResult Info(string param)
        {
            var model = new List<Tuple<string, string, int>>();
            switch (param)
            {
                case "base":
                    model = BaseService.GetCachedSQL();
                    break;
                case "store":
                    model = StoreService.GetCachedSQL();
                    break;
                case "passport":
                    model = PassportService.GetCachedSQL();
                    break;
                case "order":
                    model = OrderService.GetCachedSQL();
                    break;
                case "extra":
                    model = ExtraService.GetCachedSQL();
                    break;
            }

            return PartialView(model);
        }

        public void Purge(string param)
        {
            switch (param)
            {
                case "base":
                    BaseService.PurgeQueryCache();
                    break;
                case "store":
                    StoreService.PurgeQueryCache();
                    break;
                case "passport":
                    PassportService.PurgeQueryCache();
                    break;
                case "order":
                    OrderService.PurgeQueryCache();
                    break;
                case "extra":
                    ExtraService.PurgeQueryCache();
                    break;
            }
        }
    }
}
